//
//  YiBaoZhiFuViewController.m
//  EJLX
//
//  Created by adc on 15/11/29.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "YiBaoZhiFuViewController.h"
#import "YiBaoZhiFuTableViewCell.h"
#import "HttpsManager.h"
#import "YiBaoZhiFu.h"
#import "YiBaoDuanXinYanZhengViewController.h"
@interface YiBaoZhiFuViewController ()

@end

@implementation YiBaoZhiFuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 20,WIDE, 44)];
    view.backgroundColor=RGB_COLOR(0x00c49f);
    [self.view addSubview:view];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(WIDE/2-35, 10, 70, 24)];
    label.text=@"易宝支付";
    label.textColor=[UIColor whiteColor];
    [view addSubview:label];
    UIButton*but1=[[UIButton alloc]initWithFrame:CGRectMake(10,7,30,30)];
    [but1 setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal];
    [but1 addTarget:self action:@selector(butClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:but1];
    _moneyLabel.userInteractionEnabled=NO;
    int a=[_yiBaoMoney intValue];
    NSString*b=[NSString stringWithFormat:@"%d",a/100];
    _moneyLabel.text=b;

    _phoneLabel.delegate=self;
    _namelabel.delegate=self;
    _shengFenZlABEL.delegate=self;
    _yinHangKaLabel.delegate=self;
    _kaLeiXingLabel.delegate=self;
    _youXiaoQiLabel.delegate=self;
    _youXiaoQiYueLabel.delegate=self;
    _cvvLabel.delegate=self;

}
-(void)butClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==3)
    {
        if (buttonIndex==1)
        {
            YiBaoDuanXinYanZhengViewController*vc=[[YiBaoDuanXinYanZhengViewController alloc]init];
            
            vc.paymentId=_paymentId;
            
            
            
            
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
    
}

//开始编辑输入框的时候，软键盘出现，执行此事件
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    CGRect frame = textField.frame;
    int offset = frame.origin.y + 32 - (self.view.frame.size.height - 240.0);//键盘高度216
    
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    
    //将视图的Y坐标向上移动offset个单位，以使下面腾出地方用于软键盘的显示
    if(offset > 0)
        self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);
    
    [UIView commitAnimations];
}

//当用户按下return键或者按回车键，keyboard消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

//输入框编辑完成以后，将视图恢复到原始状态
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)tiJiaoBut:(UIButton *)sender
{
    YiBaoZhiFu*yibao=[[YiBaoZhiFu alloc]init];
   
    yibao.name=_namelabel.text;
    yibao.YinHangKa=_yinHangKaLabel.text;
    yibao.phone=_phoneLabel.text;
    yibao.shenFenZheng=_shengFenZlABEL.text;
    // yibao.YinHangKa=_YinHangKa;
    yibao.paymentId=_paymentId;
    yibao.youXiaoQiNian=_youXiaoQiLabel.text;
    yibao.youXiaoQiYue=_youXiaoQiYueLabel.text;
    yibao.cvv=_cvvLabel.text;
  //  NSLog(@"......%@",_name);
    [HttpsManager requestYiBaoZhiFu:yibao completion:^(int paycode, NSString *paymsg)
     {
         NSString*str=[NSString stringWithFormat:@"%d",paycode];
         
         if ([str isEqualToString:@"8"])
         {
             UIAlertView*alt=[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"交易存在风险是否需要验证" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去验证", nil];
             alt.tag=3;
             [alt show];
         }
        else
        {
            SHOW_ALERT(paymsg);
            return ;
        }
         
     }];

}
@end
